<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>分期付款贷款计算器</title>
<style>
  body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: #f4f4f4;
  }
  .container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  }
  input[type="number"], button {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 1px solid #ddd;
    border-radius: 4px;
  }
  button {
    background-color: #5cb85c;
    color: white;
    border: none;
    cursor: pointer;
  }
  button:hover {
    background-color: #4cae4c;
  }
  .result {
    margin-top: 20px;
    padding: 10px;
    background-color: #dff0d8;
    border: 1px solid #d6e9c6;
    border-radius: 4px;
  }
</style>
</head>
<body>
<div class="container">
  <h2>分期付款贷款计算器</h2>
  <label for="loanAmount">贷款总额:</label>
  <input type="number" id="loanAmount" placeholder="请输入贷款总额">

  <label for="annualInterestRate">年利率 (%):</label>
  <input type="number" id="annualInterestRate" placeholder="请输入年利率">

  <label for="loanTerm">分期期数 (月):</label>
  <input type="number" id="loanTerm" placeholder="请输入分期期数">

  <label for="downPayment">首付款比例 (%):</label>
  <input type="number" id="downPayment" placeholder="请输入首付款比例">

  <button onclick="calculateInstallment()">计算分期付款</button>

  <div id="result" class="result"></div>
</div>

<script>
function calculateInstallment() {
  const loanAmount = document.getElementById('loanAmount').value;
  const annualInterestRate = document.getElementById('annualInterestRate').value;
  const loanTerm = document.getElementById('loanTerm').value;
  const downPayment = document.getElementById('downPayment').value;

  // 计算首付款后的贷款金额
  const loanAfterDownPayment = loanAmount * (1 - downPayment / 100);

  // 月利率
  const monthlyInterestRate = annualInterestRate / 100 / 12;

  // 每月还款金额
  const monthlyPayment = (loanAfterDownPayment * monthlyInterestRate) / (1 - Math.pow(1 + monthlyInterestRate, -loanTerm));

  // 显示结果
  document.getElementById('result').textContent = `每月还款金额: ¥${monthlyPayment.toFixed(2)}`;
}
</script>
</body>
</html>